package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonKeyBean;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.callback.KeyboardAdapterImpl;

import java.util.List;

/**
 * Created by shiweiwei on 2017/12/26.
 */

public class CartoonKeyboardAdapter extends CommonRecycleViewAdapter<CartoonKeyBean> {


    public KeyboardAdapterImpl getListener() {
        return listener;
    }

    public void setListener(KeyboardAdapterImpl listener) {
        this.listener = listener;
    }

    KeyboardAdapterImpl listener;


    public CartoonKeyboardAdapter(Context mContext, List<CartoonKeyBean> itemDatas) {
        super(mContext, R.layout.cartoon_keyboard_item_layout, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, CartoonKeyBean item, final int position) {

        final TextView key_text = customViewHold.getView(R.id.key_item);
        RelativeLayout key_item_layout = customViewHold.getView(R.id.key_item_layout);
        key_item_layout.setBackgroundResource(R.mipmap.cartoon_key_item_bg);
        if ("delete".equals(item.getLowerValue())) {
            key_text.setText("delete");
            key_text.setVisibility(View.GONE);
            key_item_layout.setBackgroundResource(R.mipmap.cartoon_keyboard_delete);
        } else if (item.isLower()) {
            key_text.setVisibility(View.VISIBLE);
            key_item_layout.setBackgroundResource(R.mipmap.cartoon_key_item_bg);
            key_text.setText(item.getLowerValue());
        }
        else {
            key_text.setVisibility(View.VISIBLE);
            key_item_layout.setBackgroundResource(R.mipmap.cartoon_key_item_bg);
            key_text.setText(item.getUpperValue());
        }

        key_item_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (listener != null) {
                    listener.onClick(key_text.getText().toString());
                }

            }
        });

    }
}
